import { message } from 'antd';

import api from '../../api';

export const namespace = 'creditSpreadAnalysisM';

export default {
  namespace,
  state: {
    // 组件内设置sorter，width等属性
  },
  effects: {
    // 获取前一交易日
    *getBankTradingDate({ payload, callback }, { call }) {
      const res = yield call(api.getTradingDate, payload);
      if (res && res.message == 'success') {
        callback(res.data);
      } else {
        message.error(res?.message);
      }
    },
    // 查询城投债信用利差分析table
    *querySpreadAnalysis({ payload, callback }, { call, put }) {
      try {
        const data1 = [
          {
            province: '安徽省',
            creditSpreads: 62.4,
            creditInterestDiff: 21750,
          },
          {
            province: '江苏省',
            creditSpreads: 56.9,
            creditInterestDiff: 34120,
          },
          {
            province: '浙江省',
            creditSpreads: 41.8,
            creditInterestDiff: 48370,
          },
          {
            province: '青海省',
            creditSpreads: 18.6,
            creditInterestDiff: 57370,
          },
          {
            province: '云南省',
            creditSpreads: 17.8,
            creditInterestDiff: 67582,
          },
          {
            province: '贵州省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
          },
        ];
        const data2 = [
          {
            province: '山东省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: -0.7,
            pastSixMonths: -0.77,
            pastOneYear: -2.77,
          },
          {
            province: '江苏省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 1.5,
            pastSixMonths: 0.9,
            pastOneYear: 3.9,
          },
          {
            province: '安徽省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: -3.2,
            pastSixMonths: 4.2,
            pastOneYear: -4.8,
          },
          {
            province: '浙江省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 4.5,
            pastSixMonths: 5,
            pastOneYear: 4.9,
          },
          {
            province: '天津省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.3,
            pastSixMonths: -0.34,
            pastOneYear: 1.34,
          },
          {
            province: '上海省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.7,
            pastSixMonths: -0.77,
            pastOneYear: 2.77,
          },
          {
            province: '重庆省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: -1.5,
            pastSixMonths: -0.9,
            pastOneYear: 3.9,
          },
          {
            province: '湖南省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 3.2,
            pastSixMonths: 4.2,
            pastOneYear: -4.8,
          },
          {
            province: '西藏省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 4.5,
            pastSixMonths: -5,
            pastOneYear: 4.9,
          },
          {
            province: '贵州省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.14,
            pastSixMonths: 0.54,
            pastOneYear: 4.9,
          },
          {
            province: '新疆维吾尔自治区',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 2,
            pastSixMonths: 0.54,
            pastOneYear: 0.34,
          },
          {
            province: '宁夏回族自治区',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: -0.3,
            pastSixMonths: -0.34,
            pastOneYear: 0.34,
          },
          {
            province: '广西省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.7,
            pastSixMonths: -0.77,
            pastOneYear: -2.77,
          },
          {
            province: '黑龙江省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 1.5,
            pastSixMonths: -0.9,
            pastOneYear: -3.9,
          },
          {
            province: '吉林省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 4.5,
            pastSixMonths: 5,
            pastOneYear: -4.9,
          },
          {
            province: '辽宁省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.14,
            pastSixMonths: 0.54,
            pastOneYear: 0.34,
          },
          {
            province: '河北省',
            creditSpreads: 19.8,
            creditInterestDiff: 80892,
            pastThreeMonths: 0.3,
            pastSixMonths: 0.34,
            pastOneYear: 1.34,
          },
        ];
        const data1WithCity = data1.map((v, index) => ({ ...v, city: `蚌埠市${index}` }));
        const data2WithCity = data2.map((v, index) => ({ ...v, city: `南京市${index}` }));
        const res = yield call(api.creditSpreadAnalysis.getCreditSpreadAnalysisTable, payload);
        if (res?.code === 0) {
          // if (payload.dimension === '4' && payload.creditOrChange === '1') {
          //   // 信用利差
          //   callback({
          //     dataSource: payload.rateDiff == '1' ? data1 : data1WithCity,
          //   });
          // } else if (payload.dimension === '4' && payload.creditOrChange === '2') {
          //   // 利差变动
          //   callback({
          //     dataSource: payload.rateDiff == '1' ? data2 : data2WithCity,
          //   });
          // } else {
          //   callback(res.data);
          // }
          callback(res.data);
          yield put({
            type: 'setState',
            payload: {
              columns: res.data.columns,
            },
          });
        } else {
          // const dataSource = [];
          // // eslint-disable-next-line no-plusplus
          // for (let i = 0; i < 5; i++) {
          //   dataSource.push({
          //     id: i,
          //     province: i,
          //     creditSpreads_collectivity: i,
          //     creditSpreads_AAA: i,
          //     creditSpreads_AAPlus: i,
          //     creditSpreads_AA: i,
          //     creditSpreads_province: i,
          //     creditSpreads_city: i,
          //     creditSpreads_district: i,
          //     creditSpreads_nationalZone: i,
          //     creditSpreads_provinceZone: i,
          //   });
          // }
          // callback({ dataSource });
          // const columns = [
          //   {
          //     title: '省份',
          //     dataIndex: 'province',
          //     key: 'province',
          //   },
          //   {
          //     title: '城市',
          //     dataIndex: 'city',
          //     key: 'city',
          //   },
          //   {
          //     title: '信用利差（bp）',
          //     align: 'center',
          //     children: [
          //       {
          //         title: '总体',
          //         dataIndex: 'creditSpreads_collectivity',
          //         key: 'creditSpreads_collectivity',
          //       },
          //       {
          //         title: 'AAA',
          //         dataIndex: 'creditSpreads_AAA',
          //         key: 'creditSpreads_AAA',
          //       },
          //       {
          //         title: 'AA+',
          //         dataIndex: 'creditSpreads_AAPlus',
          //         key: 'creditSpreads_AAPlus',
          //       },
          //       {
          //         title: 'AA',
          //         dataIndex: 'creditSpreads_AA',
          //         key: 'creditSpreads_AA',
          //       },
          //     ],
          //   },
          //   {
          //     title: '信用利差分位数',
          //     align: 'center',
          //     children: [
          //       {
          //         title: '总体',
          //         dataIndex: 'creditSpreadsQuantiles_collectivity',
          //         key: 'creditSpreadsQuantiles_collectivity',
          //       },
          //       {
          //         title: 'AAA',
          //         dataIndex: 'creditSpreadsQuantiles_AAA',
          //         key: 'creditSpreadsQuantiles_AAA',
          //       },
          //       {
          //         title: 'AA+',
          //         dataIndex: 'creditSpreadsQuantiles_AAPlus',
          //         key: 'creditSpreadsQuantiles_AAPlus',
          //       },
          //       {
          //         title: 'AA',
          //         dataIndex: 'creditSpreadsQuantiles_AA',
          //         key: 'creditSpreadsQuantiles_AA',
          //       },
          //     ],
          //   },
          // ];
          // yield put({
          //   type: 'setState',
          //   payload: {
          //     columns,
          //   },
          // });
          message.error(res?.msg || '查询失败!');
        }
      } catch (e) {
        console.log(e);
      }
    },
    *getRegionalCreditSpreadChart({ payload, callback }, { call }) {
      const res = yield call(api.creditSpreadAnalysis.regionalCreditSpreadChart, payload);
      if (res?.code === 0) {
        callback(res.data);
      } else {
        // const xAxis = ['2018-02-16', '2018-03-16', '2018-04-16', '2018-05-16', '2018-06-16', '2018-07-16', '2018-08-16'];
        // const series = [
        //   {
        //     name: '邮件营销',
        //     data: [-120, 0, -101, -134, -90, -230, -210],
        //   },
        //   {
        //     name: '联盟广告',
        //     data: [100, 100, 191, 234, 290, 330, 310],
        //   },
        //   {
        //     name: '视频广告',
        //     data: [200, 200, 201, 154, 190, 330, 410],
        //   },
        //   {
        //     name: '直接访问',
        //     data: [-320, -332, -301, -334, -390, -330, -320],
        //   },
        //   {
        //     name: '搜索引擎',
        //     data: [820, 932, 901, 934, 1290, 1330, 1320],
        //   },
        // ];
        // callback({
        //   xAxis, series,
        // });
        message.error(res?.msg);
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
